package main

import (
	"net"
	"fmt"
	"io"
)

func main() {
	tcpaddr, _ := net.ResolveTCPAddr("tcp4", ":9527")
	tcplistener, _ := net.ListenTCP("tcp4", tcpaddr)
	fmt.Println("正在连接，等待客户端接入")
	num:=0
for {
		conn, _ := tcplistener.Accept()
		num++
		fmt.Println("客户端连入总数：",num)


		go func() {
		for {
				bs := make([]byte, 512)
				n, err := conn.Read(bs)
				if err == io.EOF||string(bs[:n])=="over" {
					fmt.Println("客户端断开连接了,结束")
					num--
					break
				}
				fmt.Println("客户端", conn.RemoteAddr(), "说：", string(bs[:n]))
				conn.Write([]byte(string(bs[:n])))
			}
		}()
	conn.Close()
	}


}
